from common import *
#from common.hand import *
import hand

class Player(object):
    
	_bust = False
	_stand = False
	_blackjack = False
	_21 = False
	hands = []
	_current_hand = None
	_bank = 500
	_current_bet = 0
	
	def __init__(self, id=None, name=''):
		self.id = id
		self.name = name
    
	def _get_bank(self):
		return self._bank
	def _set_bank(self, val):
		self._bank = val
	bank = property(_get_bank, _set_bank)
    
	def _get_current_bet(self):
		return self._current_bet
	def _set_current_bet(self,bet):
		self._current_bet = bet
		self._bank -= bet
	current_bet = property(_get_current_bet, _set_current_bet)
    
	def _get_stand(self):
		return self._stand
	is_standing = property(_get_stand)
    
	def stand(self):
		self._stand = True
        
	def _get_bust(self):
		return self._bust
	is_bust = property(_get_bust)
    
	def new_hand(self, card1, card2):
		self.hands = []
		self.hands.append(hand.Hand(card1, card2))
		self._current_hand = self.hands[0]
		if self._current_hand.total == 21:
			self._blackjack = True
    
	def _get_current_hand(self):
		if self._current_hand != None:
			return self._current_hand.cards
		else:
			return None
	current_hand = property(_get_current_hand)
        
	def _get_total(self):
		return self._current_hand.total
	total = property(_get_total)
    
	def display_total(self):
		print self._current_hand.total
    
	def hit(self, card):
		card.display()
		self._current_hand.deal_card(card)
		if self._current_hand.total == 21:
			self._21 = True
		if self._current_hand.total > 21:
			self._bust = True
			print "BUST!"
        
	def display_hand(self):
		print "\n"
		print self.name
		self._current_hand.display_hand()
    
    
            
	def status(self):
		self.display_hand()
		self.display_total()
    
	def reset(self):
		self._bust = False
		self._stand = False
		self._current_bet = False
		self._blackjack = False
		self._21 = False